package com.info.zhiduoduo.repository.mapper.taxer;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.taxer.TaxerInviteCodeDto;
import com.info.zhiduoduo.repository.entity.taxer.TaxerInviteCode;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  注册邀请码 Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2019-12-08
 */
public interface TaxerInviteCodeMapper extends BaseMapper<TaxerInviteCode> {

	@Select(" select * from zdd_taxer_invite_code tic where tic.invite_code = #{code} ")
	TaxerInviteCode selectByCode(String code);

	@Select(" select tic.*,( select IFNULL(SUM(tp.amount), 0) from zdd_maker m " +
			" left join zdd_taxer_payment tp on tp.userid = m.userid and tp.type = 1 and tp.state = 2 and tp.deleted = 0 " +
			" where m.taxer_invite_code = tic.invite_code) as totalAmount " +
			" from zdd_taxer_invite_code tic " +
			" where tic.invite_name like '%${name}%'" +
			" and tic.deleted = 0 ")
	List<TaxerInviteCodeDto> selectListByName(@Param("name") String name);
}
